﻿Imports DTO
Imports System.Data.SqlClient
Public Class KhoDAO

    Function LayTheoID(ByVal id As Integer) As KhoDTO
        Dim cn As New DataProvider()
        Dim para = New SqlParameter("@MaKho", id)
        Dim dt = cn.ExecuteQuery("layIDkho", para)
        Dim kho As New KhoDTO()
        If dt.Rows.Count <> 0 Then
            kho.MaKho = Integer.Parse(dt.Rows(0).Item("Makho").ToString())
            kho.TenKho = dt.Rows(0).Item("TenKho").ToString()
        End If
        Return kho
    End Function

    Function LayTatCa() As Collections.IList
        Dim cn As New DataProvider()
        Dim array As New ArrayList
        Dim dt = cn.ExecuteQuery("layTatCacKho")
        If dt.Rows.Count <> 0 Then
            For Each dr As DataRow In dt.Rows
                Dim kho As New KhoDTO()
                kho.MaKho = Integer.Parse(dr.Item("Makho").ToString())
                kho.TenKho = dr.Item("TenKho").ToString()
                array.Add(kho)
            Next
        End If
        Return array
    End Function
    Function LayTatCaTT() As DataTable
        Dim cn As New DataProvider()
        Return cn.ExecuteQuery("layTatCacKho")
    End Function

    Sub Them(ByVal kho As KhoDTO)
        Dim cn As New DataProvider()
        Dim para As SqlParameter() = New SqlParameter(2) {}
        para(0) = New SqlParameter("@MaKho", kho.MaKho)
        para(1) = New SqlParameter("@Tenkho", kho.TenKho)
        cn.ExecuteNonQuery("InsertKho", para)
    End Sub


End Class
